<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>大事件-后台首页</title>
    <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css">
    <!-- 引入css -->
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/iconfont.css">
    <link rel="stylesheet" href="./css/index.css">
    <script src="./libs/jquery/jquery.min.js"></script>
    <!-- 导入bootstrap的js文件 -->
    <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
    <!--  -->
    <script src="./libs/echarts.js"></script>
</head>

<body>
    <div class="sider">
        <a href="#" class="logo"><img src="./images/logo02.png" alt="logo"></a>
        <div class="user_info">
            <!-- 1.添加类名 -->
            <img class="userPic" src="http://localhost:8080/icon.jpg" alt="person">
            <span>欢迎&nbsp;&nbsp;<i id="nickname">李思思</i></span>
            <b>管理员</b>
        </div>
        <!-- 左侧导航栏 -->
        <div class="menu">
            <div class="level01 active"><a href="./main_count.html" target="iframe"><i
                        class="iconfont icon-yidiandiantubiao04"></i><span>首页</span></a></div>
            <div class="level01 l2"><a href="#"><i class="iconfont icon-icon-article"></i><span>文章管理</span>
                    <b class="iconfont icon-arrowdownl"></b></a>
            </div>
            <ul class="level02">
                <li><a href="./article_list.html" target="iframe"><i
                            class="iconfont icon-previewright"></i><span>文章列表</span></a></li>
                <li><a href="./article_add.html" target="iframe"><i
                            class="iconfont icon-previewright"></i><span>发表文章</span></a></li>
                <li><a href="./article_category.html" target="iframe"><i
                            class="iconfont icon-previewright"></i><span>文章类别管理</span></a>
                </li>
            </ul>

            <div class="level01"><a href="./commen_tlist.html" target="iframe"><i
                        class="iconfont icon-comment"></i><span>评论管理</span></a></div>

            <div class="level01" id="user"><a href="./user.html" target="iframe"><i
                        class="iconfont icon-user"></i><span>个人中心</span></a></div>
        </div>
        <!-- 顶部栏 -->
        <div class="header_bar">
            <div class="user_center_link">
                <a href="./user.html">个人中心</a>
                <!-- 添加类名 -->
                <img class="userPic" src="http://localhost:8080/icon.jpg" alt="person">
                <!-- 4.添加点击事件 -->
                <a href="javascript:void(0)" onclick="logout()" class="logout"><i class="iconfont icon-tuichu"></i>
                    退出</a>
            </div>
        </div>
        <!-- 右侧主体内容 -->
        <div class="main" id="main_body">
            <iframe src="./main_count.html" frameborder="0" style="width: 100%;height:100%;" name="iframe"></iframe>
        </div>
    </div>

    <script src="./js/index.js"></script>
    <script src="./js/http.js"></script>
    <script>
        $(function () {
            // 1.点击菜单栏实现背景色改变
            set_menu_bgcolor();
            // 2.当用户点击文章管理时展开二级菜单，同时改变箭头朝下
            sild_menu();
            // 3.调用用户信息
            get_userInfo();
        })
        let deg = 90;
        // 2.点击文章管理函数
        function sild_menu() {
            // 2.3.点击箭头朝下事件
            $('.level01.l2').click(function () {
                // 2.4.展开二级菜单和收缩
                $('.level02').slideToggle();
                // 2.5.改变箭头角度
                let bobj = $(this).find('b');
                if (deg == 0) {
                    // bobj.css('transform', 'rotate(-90deg)');
                    $('.menu .level01 b').css('transform', 'rotate(-90deg)');
                    deg = 90;
                    console.log(deg);
                } else {
                    // bobj.css('transform', 'rotate(0deg)');
                    $('.menu .level01 b').css('transform', 'rotate(0deg)');
                    deg = 0;
                    console.log(deg);
                }
                // 用toggle做切换事件箭头会被隐藏
                // bobj.toggle(function () {
                //     bobj.css({ "transform": "rotate(0deg)", "display": "block !important" });
                // }, function () {
                //     bobj.css('transform', 'rotate(-90deg)');
                // })
            })
        }
        // 2.6 处理用户点击菜单以后实现背景色改变
        function set_menu_bgcolor() {
            $('.menu .level01,.menu .level02 li').click(function () {
                // console.log(111111111);
                // 移出所有的active
                $('.menu .level01,.menu .level02 li').removeClass('active');
                // 给当前点击事件添加active
                $(this).addClass('active');
            })
        }

        // 3.将用户的头像/昵称更新到对应的位置
        function get_userInfo() {
            myAjax('get', '/admin/user/info', null, function (resData) {
                // 将数据添加到指定位置
                // 头像填充
                $('.userPic').attr('src', resData.data.userPic);
                $('#nickname').html(resData.data.nickname);
            })
        }

        // 4.退出功能
        function logout() {
            // 4.1 将浏览器中本地存储中的token移除
            localStorage.removeItem('bigNews_token');
            // 4.2 将页面重新指向logo.html
            window.location = './login.html';
        }
    </script>
</body>

</html>